<?php
/**
 * Created by PhpStorm.
 * User: jieaido
 * Date: 2017/3/27
 * Time: 8:25
 */
namespace Admin\Controller;

use Org\Util\Rbac;
use Think\Controller;
use Think\Crypt\Driver\Think;

class LoginController extends Controller{
    public function Login()
    {
        $this->display();
    }

    public function Loginout()
    {
        session_unset();
        session_destroy();
        $this->redirect('admin/login/login');
    }

    public function Login_Post()
    {
        if(!IS_POST){
            $this->error('错误');
        }
        $verify=new \Think\Verify();

        if(!$verify->check(I('code'))){
            $this->error('验证码错误');
        }

        $conditon['username']=I('username');
        $conditon['userpwd']=I('password');
        $result= M('user')->where($conditon)->find();
        if($result){

            import('Org.Util.rbac');


            $_SESSION[C('USER_AUTH_KEY')] = $result['id'];
            $_SESSION['username']=$result['username'];
            if ($result['username'] == C('RBAC_SUPERADMIN')) {

                session(C('ADMIN_AUTH_KEY'), true);
            }

            Rbac::saveAccessList();

            $this->redirect('Admin/Index/Index');
        }

    }

    public function verify()
    {
        $config=array(
            'useCurve'=>false,
            'useNoise'=>false,
            'length'=>3,
            'codeSet'=>'1234567890',
            'fontSize'=>22,
            // 'imageH'=>50,
            //'imageW'=>130,

        );
        $verify=new \Think\Verify($config);

        $verify->entry();
    }
}